package Utils;

import java.sql.ResultSet;
import java.util.HashMap;
import javax.swing.JDialog;
import net.sf.jasperreports.engine.JRResultSetDataSource;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;

public class Relatorio {

    public static void relatorio(String caminho, ResultSet rs) {
        try {
            JDialog viewer = new JDialog(new javax.swing.JFrame(), "Visualização do Relatório", true);
            Utils.maximizar(viewer);

            JRResultSetDataSource jrRS = new JRResultSetDataSource(rs);
            JasperPrint jasperPrint =
                    JasperFillManager.fillReport(caminho, new HashMap(), jrRS);
            JasperViewer jpViewer = new JasperViewer(jasperPrint, false);
            viewer.getContentPane().add(jpViewer.getContentPane());
            viewer.setVisible(true);
        } catch (Exception e) {
            Msg.erroPadrao(null, "");
            e.printStackTrace();
        }
    }
}
